package com.atkxp.stustatusmasystem.Config;

import com.atkxp.stustatusmasystem.interceptor.AdminFilter;
import com.atkxp.stustatusmasystem.interceptor.StudentFilter;
import com.atkxp.stustatusmasystem.interceptor.TeacherFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;

/**
 * @author user
 * @declaration
 * @create 2023/6/4-14:27
 */
//@Configuration
public class FilterConfig {
    @Bean
    public FilterRegistrationBean<AdminFilter> adminFilterFilterRegistrationBean() {
        FilterRegistrationBean<AdminFilter> filterRegBean = new FilterRegistrationBean<>();
        filterRegBean.setFilter(new AdminFilter());
        filterRegBean.addUrlPatterns("/admin/*");
        filterRegBean.setOrder(Ordered.LOWEST_PRECEDENCE -2);
        return filterRegBean;
    }

    @Bean
    public FilterRegistrationBean<TeacherFilter> teacherFilterFilterRegistrationBean() {
        FilterRegistrationBean<TeacherFilter> filterRegBean = new FilterRegistrationBean<>();
        filterRegBean.setFilter(new TeacherFilter());
        filterRegBean.addUrlPatterns("/teacher/*");
        filterRegBean.setOrder(Ordered.LOWEST_PRECEDENCE -1);
        return filterRegBean;
    }

    @Bean
    public FilterRegistrationBean<StudentFilter> studentFilterFilterRegistrationBean() {
        FilterRegistrationBean<StudentFilter> filterRegBean = new FilterRegistrationBean<>();
        filterRegBean.setFilter(new StudentFilter());
        filterRegBean.addUrlPatterns("/student/*");
        filterRegBean.setOrder(Ordered.LOWEST_PRECEDENCE -0);
        return filterRegBean;
    }
}
